<?php

declare(strict_types=1);

namespace App\CustHub\Model;

use Hyperf\Database\Model\Relations\BelongsToMany;
use Mine\MineModel;

/**
 * @property int $id 
 * @property int $uid 
 * @property int $main_uid 
 * @property string $name 分组名称
 * @property \Carbon\Carbon $created_at 
 * @property \Carbon\Carbon $updated_at 
 * @property-read null|\Hyperf\Database\Model\Collection|ChRoom[] $rooms 
 */
class ChRoomGroup extends MineModel
{
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'ch_room_group';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'uid', 'main_uid', 'name', 'created_at', 'updated_at'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'uid' => 'integer', 'main_uid' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];

    public function rooms(): BelongsToMany
    {
        return $this->belongsToMany(ChRoom::class,'ch_room_group_map','group_id','room_id');
    }
}
